<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>库存期初建账管理</title>
<meta name="decorator" content="default"/>
<script src="${ctxStatic}/common/change/change.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	initVaccName(bsVaccineBatchno.companyCode,bsVaccineBatchno.vaccineId);
	initVaccCompanyName(bsVaccineBatchno.companyCode)
	$(".vaccineCompany").change(function(){
		var vaccId = $(this).val();
		initCompanyName($(this).val());
		if(vaccId == ""){
			initVaccCompanyName("");
		}
	});
	$(document).on("click","#union",function(){
		var $tr = $(this).closest("tr");
		var obj = {
			index : guid(),
			batchnoId : $tr.find('[data-name="id"]').attr('data-col'),
			spec : $tr.find('[data-name="spec"]').attr('data-col'),
			outBoundDate : $tr.find('[data-name="outBoundDate"]').attr('data-col'),
			batchType : $tr.find('[data-name="batchType"]').attr('data-col'),
			companyCode : $tr.find('[data-name="companyCode"]').attr('data-col'),
			companyName : $tr.find('[data-name="companyName"]').attr('data-col'),
			vaccineId : $tr.find('[data-name="vaccineId"]').attr('data-col'),
			vaccineName : $tr.find('[data-name="vaccineName"]').attr('data-col'),
			batchno : $tr.find('[data-name="batchno"]').attr('data-col'),
			secondBatchno : $tr.find('[data-name="secondBatchno"]').attr('data-col'),
			certifiCode : $tr.find('[data-name="certifiCode"]').attr('data-col'),
			type : $tr.find('[data-name="type"]').attr('data-col'),
			dose : $tr.find('[data-name="dose"]').attr('data-col')
		};
		if(obj.outBoundDate == '' || obj.outBoundDate == '-'){
			layer.msg("该批号的有效日期不能为空!");
			return;
		}
		var num_reg = /^\+?[1-9][0-9]*$/;
		if(obj.batchType == '1'){
		debugger;
			if (!num_reg.test(obj.spec)) {
				layer.msg("该批号的规格的格式不正确!");
				return;
			}
			$.ajax({
				url:"${ctx}/company/bsCompanyConfig/checkConfig",
				type: "POST",
				data:{
		              "vaccineId":    obj.vaccineId,
		              "companyCode":  obj.companyCode
		             },
				async : false,
				success:function(data){
					if(data.result == true){
						window.parent.getInfo(obj);
					}else{
						layer.msg("该批号暂不支持选用!");
						return;
					}	
				},
				error : function() {
					return;
				}
		    }); 
		}else{
			window.parent.getInfo(obj);
		}
	});
});
var bsVaccineBatchno = JSON.parse('${fns:toJson(bsVaccineBatchno)}');
function page(n,s){
	$("#pageNo").val(n);
	$("#pageSize").val(s);
	$("#searchForm").submit();
    return false;
}

function closeLayer(){
	var index=parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}
</script>
<style type="text/css">
body{
   padding:10px;
}		
#contentTable td ,#contentTable th{
	text-align: center;
	padding:1px 10px;
}
.minWidth {
	min-width: 177px;
}
</style>
</head>
<body>
	<form:form id="searchForm" modelAttribute="bsVaccineBatchno" action="${ctx}/vaccinate/bsVaccineBatchno/getList" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<table class="table table-bordered">
			<tr>
			    <th>疫苗/注射器:</th>
				<td>
					<form:select path="batchType" id="batchType" class="span2 minWidth" >
						<form:option value="" label="--请选择--"/>
						<form:options items="${fns:getDictList('batch_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
					</form:select>
				</td>
				<th>疫苗类型:</th>
				<td>
					<form:select path="type" id="type" class="span2 minWidth" >
						<form:option value="" label="--请选择--"/>
						<form:options items="${fns:getDictList('bs_vaccineInfo_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
					</form:select>
				</td>
				<th>疫苗批号：</th>
				<td>
					<form:input path="batchno" id="batchno" class="span2 minWidth" />	
				</td>
			</tr>
			<tr>
			    <th>疫苗名称:</th>
				<td>
					<form:select path="vaccineId" id="vaccineId" class="span2 minWidth vaccineCompany" >
						<form:option value=""  label="--请选择--"/>
					</form:select>
				</td>
				<th>生产企业：</th>
				<td>
					<form:select path="companyCode" id="companyCode" class="span2 minWidth changeCompany vaccCompanyName">
						<form:option value="" label="--请选择--"/> 
					</form:select>
				</td>
				<th>有效期情况</th>
			    <td>
				    <form:radiobuttons path="dateType" items="${fns:getDictList('dateType')}" itemLabel="label" itemValue="value"/>
				</td>
			</tr>
		</table>
		<div>
			<button id="btnSubmit" class="btn btn-primary" type="submit">查询</button>
			<button  class="btn btn-primary" onclick="closeLayer()" type="button">关闭窗口</button>
		</div>
	</form:form>
	
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed" >
		<thead>
			<tr>
				<shiro:hasPermission name="vaccinate:bsProduct:edit"><th>操作</th></shiro:hasPermission>
				<th>疫苗名称</th>
				<th>疫苗生产企业</th>
				<th>疫苗批号</th>
				<th>有效日期</th>
				<th>规格</th>
				<th>剂量</th>
				<th>批签发合格证明编号</th>
			</tr>
		</thead>
		<tbody id="tbody">
		<c:forEach items="${page.list}" var="bsVaccineBatchno">
			<tr>
				<td>
					<input type="button" style="border:none;background-color:#ffffff;" id="union" value="关联"/>
				</td>
				<td style="display:none"  data-name = "id" data-col = "${bsVaccineBatchno.id}">
					${bsVaccineBatchno.id}
				</td>
				<td data-name = "vaccineName" data-col = "${bsVaccineBatchno.vaccineName}">
					${bsVaccineBatchno.vaccineName}
				</td>
				<td  style="display:none" data-name = "vaccineId" data-col = "${bsVaccineBatchno.vaccineId}">
			        ${bsVaccineBatchno.vaccineId}
				</td>
				<td data-name = "companyName" data-col = "${bsVaccineBatchno.companyName}">
					${bsVaccineBatchno.companyName}
				</td>
				<td style="display:none" data-name = "companyCode" data-col = "${bsVaccineBatchno.companyCode}">
					${bsVaccineBatchno.companyCode}
				</td>
				<td data-name = "batchno" data-col = "${bsVaccineBatchno.batchno}">
				    ${bsVaccineBatchno.batchno}
					<c:if test="${not empty bsVaccineBatchno.secondBatchno}">
				        <span title="(查询批号时不需要带入亚批号)" style="color: #2fa4e7;">-${bsVaccineBatchno.secondBatchno}</span>
				    </c:if>
				</td>
				<td data-name = "outBoundDate" data-col = "${bsVaccineBatchno.outBoundDate}">
					<fmt:formatDate value="${bsVaccineBatchno.outBoundDate}" pattern="yyyy-MM-dd"/>
				</td>
				<td data-name = "spec" data-col = "${bsVaccineBatchno.spec}">
					${bsVaccineBatchno.spec}
				</td>
				<td  data-name = "dose" data-col = "${bsVaccineBatchno.dose}">
					${bsVaccineBatchno.dose}
				</td>
				<td data-name = "certifiCode" data-col = "${bsVaccineBatchno.certifiCode}">
					${bsVaccineBatchno.certifiCode}
				</td>
				<td  style="display:none" data-name = "secondBatchno" data-col = "${bsVaccineBatchno.secondBatchno}">
			        ${bsVaccineBatchno.secondBatchno}
				</td>
				<td  style="display:none" data-name = "batchType" data-col = "${bsVaccineBatchno.batchType}">
			        ${bsVaccineBatchno.batchType}
				</td>
				<td  style="display:none" data-name = "type" data-col = "${bsVaccineBatchno.type}">
			        ${bsVaccineBatchno.type}
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>